package com.hly.tool.department;

import com.hly.tool.constants.Constants;
import com.hly.tool.object.HDomainObject;
import com.matrixone.apps.domain.util.MapList;
import com.matrixone.apps.domain.util.PersonUtil;
import matrix.db.Context;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/10/21 17:16
 * @description：
 */
public class DepartmentUtil
{


    /**
     * 获取人员所在的部门
     *
     * @param context
     * @param personName
     * @return
     */
    public static MapList getPersonDepartment(Context context, String personName)
    {
        MapList result = new MapList();

        try
        {
            String personObjectID = PersonUtil.getPersonObjectID(context, personName);
            result = HDomainObject.getRelatedObjects(context, personObjectID, Constants.type_Department, Constants.rel_Member, true, false, (short) 1);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return result;
    }


    /**
     * 获取部门下的人员
     *
     * @param context
     * @param departmentId
     * @return
     */
    public static MapList getDepartmentPerson(Context context, String departmentId)
    {
        MapList result = new MapList();
        try
        {
//            Context context, String objectId, String relatedTye, String relName, boolean form, boolean to, short level
            result = HDomainObject.getRelatedObjects(context, departmentId, Constants.type_Person, Constants.rel_Member, false, true, (short) 1);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return result;
    }


}
